<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'待发送红包列表'),
	array('op'=>'ok','title'=>'已发送红包列表'),	
	array('op'=>'no','title'=>'发送失败红包列表'),	
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0);
	if(!empty($_RQ['ptitle'])){
		$pid=pdo_getcolumn('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'title like %'=>$_RQ['ptitle'].'%'),'id');
		$params['pid']=intval($_RQ['pid']);
		$return['params']['pid']=$_RQ['pid'];
	}
	if(!empty($_RQ['nickname'])){
		$mid=pdo_getcolumn('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'nickname like %'=>$_RQ['nickname'].'%'),'mid');
		$params['mid']=$mid;
		$return['params']['mid']=$mid;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_quan_feelog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$pitem=pdo_get('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pid']));
			$user=pdo_get('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid']));
			$juser=pdo_get('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$pitem['mid']));
			$item['ptitle']=$opus['title'];
			$item['fnickname']=$user['nickname'];
			$item['favatar']=$user['avatar'];
			$item['jnickname']=$juser['nickname'];
			$item['javatar']=$juser['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单编号','type'=>'string'),
			array('name'=>'ptitle','title'=>'作品名称','type'=>'string'),
			array('name'=>'fnickname','title'=>'发送人昵称','type'=>'string'),
			array('name'=>'favatar','title'=>'发送人头像','type'=>'image'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'jnickname','title'=>'接收人昵称','type'=>'string'),
			array('name'=>'javatar','title'=>'接收人头像','type'=>'image'),
			array('name'=>'ispay','title'=>'支付?','type'=>'radio','options'=>'ispay'),
			array('name'=>'status','title'=>'红包代发','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'ptitle','width'=>15,'title'=>'作品名称','type'=>'string'),
			array('name'=>'fnickname','width'=>15,'title'=>'发送人昵称','type'=>'string'),
		)
	);
	$return['ispay']=array('0'=>'待支付','1'=>'已支付','2'=>'支付失败');
	$return['status']=array('0'=>'待审核','1'=>'已发送','2'=>'发送失败');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='ok'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=1;
	if(!empty($_RQ['ptitle'])){
		$pid=pdo_getcolumn('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'title like %'=>$_RQ['ptitle'].'%'),'id');
		$params['pid']=intval($_RQ['pid']);
		$return['params']['pid']=$_RQ['pid'];
	}
	if(!empty($_RQ['nickname'])){
		$mid=pdo_getcolumn('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'nickname like %'=>$_RQ['nickname'].'%'),'mid');
		$params['mid']=$mid;
		$return['params']['mid']=$mid;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_quan_feelog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$opus=pdo_get('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pid']));
			$user=pdo_get('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid']));
			$juser=pdo_get('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$opus['mid']));
			$item['ptitle']=$opus['title'];
			$item['rtitle']=$reply['title'];
			$item['fnickname']=$user['nickname'];
			$item['favatar']=$user['avatar'];
			$item['jnickname']=$juser['nickname'];
			$item['javatar']=$juser['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单编号','type'=>'string'),
			array('name'=>'ptitle','title'=>'作品名称','type'=>'string'),
			array('name'=>'fnickname','title'=>'发送人昵称','type'=>'string'),
			array('name'=>'favatar','title'=>'发送人头像','type'=>'image'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'jnickname','title'=>'接收人昵称','type'=>'string'),
			array('name'=>'javatar','title'=>'接收人头像','type'=>'image'),
			array('name'=>'ispay','title'=>'支付?','type'=>'radio','options'=>'ispay'),
			array('name'=>'status','title'=>'红包代发','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'ptitle','width'=>15,'title'=>'作品名称','type'=>'string'),
			array('name'=>'fnickname','width'=>15,'title'=>'发送人昵称','type'=>'string'),
		)
	);
	$return['status']=array('0'=>'待审核','1'=>'已发送','2'=>'发送失败');
	$return['ispay']=array('0'=>'待支付','1'=>'已支付','2'=>'支付失败');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='no'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=2;
	if(!empty($_RQ['ptitle'])){
		$pid=pdo_getcolumn('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'title like %'=>$_RQ['ptitle'].'%'),'id');
		$params['pid']=intval($_RQ['pid']);
		$return['params']['pid']=$_RQ['pid'];
	}
	if(!empty($_RQ['nickname'])){
		$mid=pdo_getcolumn('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'nickname like %'=>$_RQ['nickname'].'%'),'mid');
		$params['mid']=$mid;
		$return['params']['mid']=$mid;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_quan_feelog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$opus=pdo_get('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pid']));
			$user=pdo_get('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid']));
			$juser=pdo_get('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$opus['mid']));
			$item['ptitle']=$opus['title'];
			$item['fnickname']=$user['nickname'];
			$item['favatar']=$user['avatar'];
			$item['jnickname']=$juser['nickname'];
			$item['javatar']=$juser['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单编号','type'=>'string'),
			array('name'=>'ptitle','title'=>'作品名称','type'=>'string'),
			array('name'=>'fnickname','title'=>'发送人昵称','type'=>'string'),
			array('name'=>'favatar','title'=>'发送人头像','type'=>'image'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'jnickname','title'=>'接收人昵称','type'=>'string'),
			array('name'=>'javatar','title'=>'接收人头像','type'=>'image'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'error_msg','title'=>'错误原因','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'ptitle','width'=>15,'title'=>'作品名称','type'=>'string'),
			array('name'=>'fnickname','width'=>15,'title'=>'发送人昵称','type'=>'string'),
		)
	);
	$return['status']=array('0'=>'待审核','1'=>'已发送','2'=>'发送失败');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_quan_feelog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
